/**   
 * @Title: Particle.java 
 * @Package com.forever.thread.gui 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author leo   
 * @date 2014-9-16 上午11:17:57
 */
package com.forever.thread.gui;

import java.awt.Graphics;
import java.util.Random;

/**
 * @ClassName: Particle
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author leo
 * @date 2014-9-16 上午11:17:57
 * 
 */
public class Particle {

	protected int x;
	protected int y;
	protected final Random rng = new Random();

	/**
	 * @param x
	 * @param y
	 */
	protected Particle(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}

	public synchronized void move() {
		x += rng.nextInt(10) - 5;
		y += rng.nextInt(20) - 10;
	}

	public synchronized void draw(Graphics g) {
		int lx, ly;
		synchronized (this) {
			lx = x;
			ly = y;
		}
		g.drawRect(lx, ly, 10, 10);
	}
}